package com.atguigu.eduservice.controller.front;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.Teacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
public class TeacherFrontController {

    @Autowired
    TeacherService teacherService;

    @Autowired
    EduCourseService eduCourseService;

    //分页查询讲师的方法
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable int page,@PathVariable int limit){
        Page<Teacher> pageTeahcer = new Page<>(page,limit);
        Map<String,Object> map=teacherService.getTeacherFrontList(pageTeahcer);
        return R.ok().data("map",map);
    }

    //根据讲师id查询讲师的数据
    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id){
        Teacher teacher = teacherService.getById(id);
        //根据讲师id查询讲师的所有课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> list = eduCourseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",list);
    }

}
